export function sortBy<T>(
  array: T[],
  getter: (item: T) => string | number | boolean,
): T[] {
  const sortedArray = [...array];
  sortedArray.sort((a, b) =>
    String(getter(a)).localeCompare(String(getter(b)), 'en', {
      numeric: true,
      ignorePunctuation: true,
    }),
  );
  return sortedArray;
}

export function toggleListItem<T>(list: T[], item: T): T[] {
  const itemIndex = list.indexOf(item);
  if (itemIndex === -1) {
    return [...list, item];
  }
  return [...list.slice(0, itemIndex), ...list.slice(itemIndex + 1)];
} 